import { createStore } from 'vuex';

export default createStore({
  state: {
    user: {
      isLoggedIn: false,
      username: null,
      token: null
    }
  },
  mutations: {
    SET_USER(state, user) {
      state.user = {
        isLoggedIn: true,
        username: user.username,
        token: user.token
      };
    },
    CLEAR_USER(state) {
      state.user = {
        isLoggedIn: false,
        username: null,
        token: null
      };
    }
  },
  actions: {
    signIn({ commit }, user) {
      commit('SET_USER', user);
    },
    signOut({ commit }) {
      commit('CLEAR_USER');
      localStorage.removeItem('token');
      localStorage.removeItem('username');
    }
  },
  getters: {
    isLoggedIn: state => state.user.isLoggedIn,
    username: state => state.user.username,
    token: state => state.user.token
  }
}); 